home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / Pascal OS8 / Gadgets / GadgetsDoc.p < prev    next >
Encoding:
Text File  |  1998-10-30  |  2.3 KB  |  149 lines  |  [TEXT/CWIE]

  1. { GadgetsDoc.p -- document-level functions }
  2.  
  3. Unit GadgetsDoc;
  4. Interface
  5.  
  6. Uses
  7.     Types,
  8.     Events,
  9.     Files,
  10.     Menus,
  11.     GadgetsEngine,
  12.     AMDoc;
  13.  
  14. type
  15.     GadgetsDoc        = object (AMDoc)
  16.  
  17.     {data members}
  18.         mButtonsPtr:        WindowPtr;
  19.         mTabbedPanelPtr:        WindowPtr;
  20.         mEditTextPtr:        WindowPtr;
  21.  
  22.     {methods - public}
  23.         Procedure Initialize; Override;
  24.  
  25.         Function  DoCommand        (inCommand:    longint): Boolean; Override;
  26.  
  27.     {methods - internal}
  28.         Procedure OpenWindows; Override;
  29.         Function  WouldCloseDoc        (windPtr:    WindowPtr): Boolean; Override;
  30.  
  31.         Function  GetEngine: GadgetsEngine;
  32.  
  33.         Procedure DoInvokeAbout;
  34.     end;
  35.  
  36. {----------}
  37. Function NewGadgetsDoc: GadgetsDoc;
  38.  
  39. {----------}
  40. Implementation
  41.  
  42. Uses
  43.     ResourceDefs,
  44.     Globals,
  45.  
  46.     AboutDialog,
  47.     DDocData,
  48.     Buttons,
  49.     DDocData,
  50.     TabbedPanel,
  51.     DDocData,
  52.     EditText,
  53.     Miscellany;
  54.  
  55. {----------}
  56. Function NewGadgetsDoc: GadgetsDoc;
  57. var
  58.     doc:        GadgetsDoc;
  59. begin
  60.     New (doc);
  61.     if doc <> nil then begin
  62.         doc.Initialize;
  63.     end;
  64.     NewGadgetsDoc := doc;
  65. end;
  66.  
  67. {----------}
  68. Procedure GadgetsDoc.Initialize;
  69. begin
  70.     inherited Initialize;
  71.  
  72.     mEngine := NewGadgetsEngine;
  73.  
  74.     mButtonsPtr := nil;
  75.     mTabbedPanelPtr := nil;
  76.     mEditTextPtr := nil;
  77. end;
  78.  
  79. {----------}
  80. Function  GadgetsDoc.GetEngine: GadgetsEngine;
  81. begin
  82.     GetEngine := GadgetsEngine (mEngine);
  83. end;
  84.  
  85. {----------}
  86. Procedure GadgetsDoc.OpenWindows;
  87. var
  88.     engine:        GadgetsEngine;
  89. Begin
  90.     engine := GetEngine;
  91.  
  92.     { replace this code to get data from someplace useful }
  93.  
  94.     CreateButtons (self, engine.GetDocData);
  95.     CreateTabbedPanel (self, engine.GetDocData);
  96.     CreateEditText (self, engine.GetDocData);
  97. End;
  98.  
  99. {----------}
  100. Function GadgetsDoc.WouldCloseDoc (
  101.     windPtr:        WindowPtr): Boolean;
  102. var
  103.     numOpen:        integer;
  104. Begin
  105.     numOpen := 0;
  106.  
  107.     if mButtonsPtr <> nil then        numOpen := numOpen + 1;
  108.     if mTabbedPanelPtr <> nil then        numOpen := numOpen + 1;
  109.     if mEditTextPtr <> nil then        numOpen := numOpen + 1;
  110.  
  111.     WouldCloseDoc := (numOpen <= 1);
  112. End;
  113.  
  114. {----------}
  115. Procedure GadgetsDoc.DoInvokeAbout;
  116. var
  117.     dummy:        integer;
  118. begin
  119.     if GetAboutDialog then begin
  120.         { do something }
  121.     end;
  122. end;
  123.  
  124. {----------}
  125. Function GadgetsDoc.DoCommand (
  126.     inCommand:        longint): Boolean;
  127. begin
  128.     DoCommand := true;
  129.     case inCommand of
  130.         cmdSave:
  131.                 DoSave;
  132.         cmdSaveAs:
  133.                 DoSaveAs;
  134.         cmdRevert:
  135.                 DoRevert;
  136.         cmdPageSetup:
  137.                 DoPageSetup;
  138.         cmdPrint:
  139.                 DoPrint;
  140.         cmdInvokeAbout:
  141.                 DoInvokeAbout;
  142.  
  143.         otherwise
  144.                 DoCommand := false;
  145.     end; {case}
  146. end;
  147.  
  148. end.
  149.